<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="hardcode2013.*" %>

<html>
  <head>
    <link type="text/css" rel="stylesheet" href="/stylesheets/main.css" />
    
    <script type="text/javascript">
    function floatInputOnChange(input) {
 	   if (! input.value.match("^[0-9]*(\.[0-9]{1,2})?$")) input.value = "";
    }
    function floatInputOnKeyPress(evt) {
        var charCode = (evt.which) ? evt.which : event.keyCode;
        if (charCode != 46 && charCode > 31 && (charCode < 48 || charCode > 57))
           return false;
        else
	        return true;
    }
    </script>
  </head>
  
  <body>
    <%@include file="include_header.jsp" %>
  
	<%
	if (profile != null) {
		String itemKeyStr = request.getParameter("item");

		ItemProfile item = null;
		if (itemKeyStr != null)
			item = ItemServ.getItemProfile(itemKeyStr);
		
		%>
		<fieldset>
			<legend>Send Mail</legend>
		    <form action="/mail" method="post">
				Item: <%= (item != null ? EncodeUtil.encodeHtml(item.getTitle()) : "-")%><br>
				<% if (item != null) { %><input type="hidden" name="item_key" value="<%= EncodeUtil.encodeHtml(item.getKeyStr()) %>"><% } %>
				<% if (item != null) { %>Original Price: <%= EncodeUtil.encodeHtml(item.getPrice()) %><br><% } %>
				Recipient: <input type="text" name="recipient" <%= (item != null ? " disabled " + "value=\"" + EncodeUtil.encodeHtml(item.getSeller()) + "\"" : "") %>>
				<% if (item == null) { %>(Split multiple recipients with commas)<% } %>
				<br>
				Title: <input type="text" name="title" <%= (item != null ? "value=\"" + "RE: " + EncodeUtil.encodeHtml(item.getTitle()) + "\"" : "") %>><br>
				Content:<br><textarea name="content" rows="5" cols="50"></textarea><br>	      
				<input type="hidden" name="action" value="create_message">
				<input type="hidden" name="redirect" value="/mail.jsp">
				<input type="hidden" name="redirect_error" value="<%= "/send_mail.jsp" + (itemKeyStr != null ? "?item=" + EncodeUtil.encodeUrl(itemKeyStr) : "") %>">
				<input type="hidden" name="auth_key" value="<%= SessionUtil.getAuthKey(request) %>">
				<input type="submit" value="Send Mail" />
		    </form>
	    </fieldset>
		<%
	}
	%>
  </body>
</html>